//
//  XMChatVoiceMessageOthersTableViewCell.m
//  XMenSwift
//
//  Created by Jason on 2022/9/19.
//

#import "XMChatVoiceMessageOthersTableViewCell.h"
#import <Masonry/Masonry.h>
#import "WZMInputHelper.h"

@interface XMChatVoiceMessageOthersTableViewCell()

@property (strong, nonatomic) UILabel *contenLabel;

@property (strong, nonatomic) UIImageView *unreadImageView;

@property (strong, nonatomic) UIButton *unreadBtnImage;


@end

@implementation XMChatVoiceMessageOthersTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self steupUi];
    }
    return self;
}

- (void)steupUi {
    
    UIView *bgView = [[UIView alloc] init];
    [self.contentView addSubview:bgView];
    [bgView addSubview:self.userImageView];
    
    [bgView addSubview:self.nickLabel];

    UILabel *contenLabel = [[UILabel alloc] init];
    contenLabel.font = [UIFont systemFontOfSize:14.0];
    contenLabel.textColor = [UIColor blackColor];
    contenLabel.text = @"";
    contenLabel.numberOfLines = 1;
    self.contenLabel = contenLabel;
    
    
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView);
    }];
    
    [self.userImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(bgView).offset(10);
        make.left.equalTo(bgView).offset(10);
        make.width.mas_equalTo(50);
        make.height.mas_equalTo(50);

    }];
    
    [self.nickLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.userImageView.mas_top);
        make.left.equalTo(self.userImageView.mas_right).offset(10);
        make.right.equalTo(bgView).offset(-10);
        make.height.mas_equalTo(20);

    }];
    
    UIView *bubbleBgView = [[UIView alloc] init];
    [bgView addSubview:bubbleBgView];
    [bubbleBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.nickLabel.mas_bottom).offset(5);
        make.left.equalTo(self.nickLabel.mas_left);
        make.bottom.equalTo(bgView).offset(-10);
//        NSInteger maxW = [UIScreen mainScreen].bounds.size.width - 120;
        //此处拓展模型动态更改约束
//        make.width.mas_lessThanOrEqualTo(maxW);
        make.width.mas_equalTo(150);
        make.height.mas_equalTo(40);
    }];
    
    [bubbleBgView addSubview:self.bubbleImageView];
    [self.bubbleImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(bubbleBgView);
    }];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    self.unreadBtnImage = button;
    button.userInteractionEnabled = NO;
    [button setImage:[WZMInputHelper otherImageNamed:@"wzm_chat_voice_1"] forState:UIControlStateNormal];
    [bubbleBgView addSubview:button];
    [button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(bubbleBgView).offset(15);
        make.centerY.equalTo(bubbleBgView.mas_centerY);
        make.width.mas_equalTo(12);
        make.height.mas_equalTo(15);
    }];
    
    [bubbleBgView addSubview:contenLabel];
    [contenLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(bubbleBgView).offset(10);
        make.left.equalTo(button.mas_right).offset(10);
        make.bottom.equalTo(bubbleBgView).offset(-10);
        make.right.equalTo(bubbleBgView).offset(-10);
    }];
    
    UIImageView *unreadImageView = [[UIImageView alloc] init];
    unreadImageView.backgroundColor = [UIColor redColor];
    self.unreadImageView = unreadImageView;
    [bgView addSubview:unreadImageView];
    [unreadImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(bubbleBgView);
        make.left.equalTo(bubbleBgView.mas_right).offset(4);
        make.width.mas_equalTo(8);
        make.height.mas_equalTo(8);
    }];
    unreadImageView.layer.masksToBounds = YES;
    unreadImageView.layer.cornerRadius = 4;
    
    
}

- (void)setConfig:(WZMChatMessageModel *)model {
    [super setConfig:model];
    self.contenLabel.text = [NSString stringWithFormat:@"%@''",@(model.duration)];
}

@end
